package com.qlk.odcinterface.manager.impl;

import java.util.List;

import com.qlk.common.manager.BaseManager;
import com.qlk.common.utils.page.PageUtil;
import com.qlk.odcinterface.domain.PmsCouponChannel;
import com.qlk.odcinterface.domain.query.PmsCouponChannelQuery;
import com.qlk.odcinterface.dao.PmsCouponChannelDao;
import com.qlk.odcinterface.manager.PmsCouponChannelManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * PmsCouponChannelManager接口的实现类
 * 
 * @author zhaoyanan
 * @version 2016-4-14 14:11:36
 * 
 */
@Component
public class PmsCouponChannelManagerImpl extends BaseManager implements PmsCouponChannelManager {
	
    @Autowired
    private PmsCouponChannelDao pmsCouponChannelDao;

    /**
     * {@inheritDoc}
     */
    public boolean insert(final List<PmsCouponChannel> pmsCouponChannelList) {
        boolean resultFlag = false;
        if (null != pmsCouponChannelList && pmsCouponChannelList.size() > 0) {
            for (PmsCouponChannel pmsCouponChannel : pmsCouponChannelList) {
                resultFlag = pmsCouponChannelDao.insert(pmsCouponChannel);
                if (!resultFlag) {
                    throw new RuntimeException("批量新增表信息异常");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean insert(PmsCouponChannel pmsCouponChannel) {
        return pmsCouponChannelDao.insert(pmsCouponChannel);
    }

    /**
     * {@inheritDoc}
     */
    public boolean update(final PmsCouponChannel pmsCouponChannel) {
        return pmsCouponChannelDao.update(pmsCouponChannel);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsCouponChannel> queryPmsCouponChannelList(PmsCouponChannelQuery queryBean) {
        return pmsCouponChannelDao.queryPmsCouponChannelList(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public List<PmsCouponChannel> queryPmsCouponChannelListWithPage(PmsCouponChannelQuery queryBean,
            PageUtil pageUtil) {
        if (null == queryBean) {
            queryBean = new PmsCouponChannelQuery();
        }

        // 查询总数
        int totalItem = queryPmsCouponChannelCount(queryBean);

        if (pageUtil == null) {
            pageUtil = new PageUtil();
        }
        pageUtil.setTotalRow(totalItem);
        pageUtil.init();
        
        if (totalItem > 0) {
            queryBean.setPageIndex(pageUtil.getCurPage());
            queryBean.setPageSize(pageUtil.getPageSize());
            // 调用Dao翻页方法
            return pmsCouponChannelDao.queryPmsCouponChannelListWithPage(queryBean);
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public int queryPmsCouponChannelCount(PmsCouponChannelQuery queryBean) {
        return pmsCouponChannelDao.queryPmsCouponChannelCount(queryBean);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(PmsCouponChannel pmsCouponChannel) {
        return pmsCouponChannelDao.delete(pmsCouponChannel);
    }

    /**
     * {@inheritDoc}
     */
    public PmsCouponChannel getPmsCouponChannelById(Integer id) {
        return pmsCouponChannelDao.getPmsCouponChannelById(id);
    }

    /**
     * {@inheritDoc}
     */
    public boolean delete(final PmsCouponChannel[] pmsCouponChannels) {
        boolean resultFlag = false;
        if (null != pmsCouponChannels && pmsCouponChannels.length > 0) {
            for (int i = 0; i < pmsCouponChannels.length; i++) {
                resultFlag = delete(pmsCouponChannels[i]);
                if (!resultFlag) {
                    throw new RuntimeException("批量删除表信息异常!");
                }
            }
        }

        return resultFlag;
    }

    /**
     * {@inheritDoc}
     */
    public boolean exist(PmsCouponChannel pmsCouponChannel) {
        return pmsCouponChannelDao.exist(pmsCouponChannel);
    }
}
